/***************************************************************************
 *   Copyright (C) 2006 by Yuri Ovcharenko                                 *
 *   amwsoft@gmail.com                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef CONSOLE_H
#define CONSOLE_H

#include <QFrame>
#include <QSize>

class QPaintEvent;
class QKeyEvent;

/**
 * @author Yuri Ovcharenko
 */

/**
 * @class Console
 * @brief Console provides vt100 like console with a special features.
 *
 * Console provides vt100 like console with a special features.
 * Console does not support all vt100 standard features.
 * Instead of this Console provides text console view ASCII symbols drawed with fixed font.
 */
class Console : public QFrame
{
    Q_OBJECT
  public:
    /**
     * @Console::Console
     * @brief Construct the Console object.
     */
    Console(QWidget *parent = 0);
    /**
     * @Console::~Console
     * @brief Destruct the Console object.
     */
    ~Console();

    virtual QSize sizeHint() const;
    virtual QSize minimumSizeHint() const;

    /**
     * @consoleSize
     * @brief return the size of console QSize object.
     * @note The size specified in characters, not pixels.
     */
    virtual QSize consoleSize();

  public slots:
    /**
     * @setConsoleSize
     * @brief set the console size in characters specified in sz.
     *
     * The size specified in characters, not pixels.
     */
    virtual void setConsoleSize(const QSize & sz);
    /**
     * @setConsoleSize
     * @brief set the console size in characters.
     *
     * Width specified in w and height specified in h.
     */
    virtual void setConsoleSize(const int w, const int h);

    /**
     * @setConsoleFont
     * @brief Set console font.
     */
    virtual void setConsoleFont(const QFont & fnt);
    /**
     * @clear
     * @brief Clear the console.
     *
     * Remove all characters from view and from internal buffer.
     */
    virtual void clear();
    /**
     * @append
     * @brief Append text at the end of viewed text.
     */
    virtual void append(const QString & text);
    /**
     * @copy
     * @brief Copy text to clipboard.
     */
    virtual void copy();
    /**
     * @paste
     * @brief Paste text from clipboard.
     */
    virtual void paste();

  protected:
    QStringList Text;
    QSize ConsoleSize;
    int xPos;

    virtual void keyPressEvent(QKeyEvent *e);
    virtual void paintEvent(QPaintEvent *);

  protected slots:
    void slotShowGeometry();
    void slotShowFontMetrics();

  signals:
    /**
     * @keyPress
     * @brief Key pressed on keyboard.
     *
     * This signal is emited whenever \a Console receives characters from keyboard.
     */
    void keyPress(const QChar & c);
};

#endif
